
#ifndef _ka_io_stream_h
#define _ka_io_stream_h

#include "ka-io/buffer.h"

namespace io {
    class IStream {
    public:
        virtual ~IStream();
        virtual size_t read(void *dest, size_t byteCount) = 0;
        virtual size_t write(const void *source, size_t byteCount) = 0;
        virtual void close() = 0;
    };
    
    class MemoryStream : public IStream {
    public:
        MemoryStream(void *start, size_t size);
        virtual ~MemoryStream();
        virtual size_t read(void *dest, size_t byteCount);
        virtual size_t write(const void *source, size_t byteCount);
        virtual void close();
        size_t getLength() const;
        size_t getPosition() const;
    private:
        uint8_t *_start;
        uint8_t *_end;
        size_t _offset;
    };
    
    class FileStream : public IStream {
    public:
        static const uint32_t READ  = 1;
        static const uint32_t WRITE = 1<<1;
        
        FileStream(const char *filePath, uint32_t flags);
        virtual ~FileStream();
        virtual size_t read(void *dest, size_t byteCount);
        virtual size_t write(const void *source, size_t byteCount);
        virtual void close();
    private:
        void *_handle;
    };

}

#endif